<?php
Yii::import('lib.widgets.CInputWidgetAdv');
/**
 * My97DatePicker 时间控件
 * {@link http://www.my97.net/dp/index.asp}
 * <pre>
 * <?php $this->widget('lib.widgets.my97date.CMy97DatePicker', array(
 *  'model' => $model,
 *  'attribute' => 'username',
 * ))?>
 * </pre>
 * @package lib.widgets.my97date
 */
class CMy97DatePicker extends CInputWidgetAdv {
	
	/**
	 * 默认的My97DatePicker js配置
	 * <br>如果设置为false或null，该参数不生效
	 * @var mixed
	 */
	public $defaultOptions = array(
		'skin'=>'hayzone',
	);
	
	/**
	 * My97DatePicker 的js配置
	 * @var array
	 */
	public $options = array();
	
	/**
	 * @see CWidget::run()
	 * @return void
	 */
	public function run() {
		$cs = Yii::app()->clientScript;
		$cs = Yii::app()->clientScript;
		$baseUrl = Yii::app()->assetManager->publish(
			dirname(__FILE__) . '/assets/', false, -1, true
		);
		
		$cs->registerScriptFile($baseUrl.'/WdatePicker.js');
		
		list($model, $attribute, $htmlOptions) = $this->resolveArgs();
		CHtml::resolveNameID($model, $attribute, $htmlOptions);
		
		$options = is_array($this->defaultOptions) 
			? array_merge($this->defaultOptions, $this->options)
			: $this->options;
		$jsOptions = CJavaScript::encode($options);
		
		if(isset($htmlOptions['onfocus'])) {
			$htmlOptions['onfocus'] = $htmlOptions['onfocus'].";WdatePicker({$jsOptions})";
		} else {
			$htmlOptions['onfocus'] = "WdatePicker({$jsOptions});";
		}
		echo CHtml::activeTextField($model, $attribute, $htmlOptions);
		
	}
	
}

?>